var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../utils/common.js');
// pages/distribut/freeze_product/freeze_product.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		opinion: {
			refrigerateimg: [],
			deviceimg: []
		},
		info: {
			shop_id: '',
			status:null
		},
		url: setting.url,
		statulist: [{
			name: '待审核',
			class: 'dsh'
		}, {
			name: '审核通过',
			class: 'shtg'
		}, {
			name: '审核不通过',
			class: 'shbtg'
		}]
	},
	changeStoreImg: function(text) {
		var that = this;
		let ppt = text.currentTarget.dataset.id
		wx.chooseImage({
			count: 1, //最多1张图片,默认9
			sizeType: ['compressed', 'original'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['camera', 'album'], // 可以指定来源是相册还是相机，默认二者都有
			success: function(res) {
				request.uploadFile1('/api/shop/UploadOne', {
					filePath: res.tempFilePaths[0],
					success: function(res) {
						if (ppt == 'refrigerateimg') {
							let data = [...that.data.opinion.refrigerateimg]
							if (text.currentTarget.dataset.index!=undefined) {
								data[text.currentTarget.dataset.index] = res.data.result
							} else {
								data.push(res.data.result)
							}
							that.setData({
								'opinion.refrigerateimg': data
							});
						}
						if (ppt == 'deviceimg') {
							let data = [...that.data.opinion.deviceimg]
							if (text.currentTarget.dataset.index!=undefined) {
								data[text.currentTarget.dataset.index] = res.data.result
							} else {
								data.push(res.data.result)
							}
							that.setData({
								'opinion.deviceimg': data
							});
						}
						//deviceimg 设备照片  refrigerateimg冷藏照片
					}
				});
			}
		});
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.getinfo()
	},
	// 删除当前图片
	deleteImg(e) {
		let list = [...this.data.opinion.deviceimg]
		list.splice(e.currentTarget.dataset.index, 1)
		this.setData({
			'opinion.deviceimg': list
		});
	},
	// 删除当前图片
	deleteImg1(e) {
		let list = [...this.data.opinion.refrigerateimg]
		list.splice(e.currentTarget.dataset.index, 1)
		this.setData({
			'opinion.refrigerateimg': list
		});
	},
	// 申请冻品
	addinfo() {
		let that = this
		request.post('/api/shop/coldApply', {
			data: {
				cold_device_images: this.data.opinion.deviceimg,
				cold_place_images: this.data.opinion.refrigerateimg
			},
			success: function(res) {
				if (res.data.status == 1) {
					wx.showToast({
						title: '已提交申请'
					})
					that.getinfo()
				} else {}
			}
		});
	},
	// 获取用户冻品申请详情
	getinfo() {
		let that = this
		request.get('/api/shop/coldApplyInfo', {
			success: function(res) {
				if (res.data.status == 1&&res.data.result) {
					let deviceimg = []
					res.data.result.cold_device_images.forEach(e => {
						deviceimg.push(e.image_url)
					})
					let refrigerateimg = []
					res.data.result.cold_place_images.forEach(e => {
						refrigerateimg.push(e.image_url)
					})
					that.setData({
						info: res.data.result,
						'opinion.deviceimg': deviceimg,
						'opinion.refrigerateimg': refrigerateimg
					});
				}
			}
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})